
package com.irdstudio.efp.esb.common.constant.dxm.reqbuilder;

import static java.util.Objects.requireNonNull;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.annotation.JSONField;
import com.irdstudio.efp.esb.common.constant.dxm.DxmEnum;

/**
 * 度小满创建请求请求对象创建器: <br>
 *
 * 0.1:caoxin:2019/3/25 10:09: 度小满创建请求请求对象创建器: <br>
 * 0.1:caoxin:2019/3/25 10:09: 使用常量更改事务类型，交易模式: <br>
 * @author caoxin
 * @return
 * @since 2019/3/25 10:09
 * @date 2019/3/25 10:09
 * @version 0.2
 */

public class DXMReqBodyBuilder {
	
	public static Builder ReqBuilder() {
		return new Builder();
	}
	
	public static class Builder{
		// 产品代码
		@JSONField(name="ProdCd")
		private String ProdCd;

		// 交易模式
		@JSONField(name="TxnMd")
		private String TxnMd;

		// 重复请求依据
		@JSONField(name="RepeatRqsBss")
		private String RepeatRqsBss ;
		// 消息域
		@JSONField(name="Message")
		private DXMMessage Message = new DXMMessage();

		
		// 创建同步请求
		public Builder buildSyncRequest() {
			this.setTxnMd(DxmEnum.TxnModel.SYNC.getValue());
			return this;
		}
		// 创建非同步请求
		public Builder buildAsyncRequest() {
			this.setTxnMd(DxmEnum.TxnModel.ASYNC.getValue());
			return this;
		}
		// 产品代码
		public Builder buildProdCd(String prodCd) {
			ProdCd = requireNonNull(prodCd,"prodCd产品代码不为空！");
			return this;
		}
		// 重复请求依据
		public Builder buildRepeatRqsBss(String repeatRqsBss) {
			RepeatRqsBss = requireNonNull(repeatRqsBss,"BdReqSn_重复请求依据不能为空！");
			return this;
		}

		public Builder buildMessageNecessityInfo(String sessionId,String evID) {
			requireNonNull(sessionId,"会话ID_授信申请流水号不能为空！");
			requireNonNull(evID,"bdTransationId_事务ID不能为空！");
			Message.setSessionId(sessionId);
			Message.setEvID(evID);
			Message.setRqsTmstmp(String.valueOf(System.currentTimeMillis()));
			return this;
		}
		
		// 创建不同的事务类型
		public Builder buildMeaageEvTypeOfApply() {
			Message.setEvTp(DxmEnum.EVTYPE.EVTYPE_APPLY.getValue());
			return this;
		}
		public Builder buildMessageEvTypeOfTransaction() {
			Message.setEvTp(DxmEnum.EVTYPE.EVTYPE_TRANSACTION.getValue());
			return this;
		}
		public Builder buildMessageEvTypeOfQuery() {
			Message.setEvTp(DxmEnum.EVTYPE.EVTYPE_QUERY.getValue());
			return this;
		}
		

		public Builder buildMessageBasicInfo(DXMBasicInfo DXMBasicInfo) {
			requireNonNull(DXMBasicInfo,"basicInfo不能为空！");
			Message.setDXMBasicInfo(DXMBasicInfo);
			return this;
		}
		

		public Builder builderExpanding(Object object) {
			requireNonNull(object,"扩展字段不能为空");
			Message.setExpanding(object);
			return this;
		}
		
		public Builder build() {
			return this;
		}

		
		public String getTxnMd() {
			return TxnMd;
		}
		public void setTxnMd(String txnMd) {
			TxnMd = txnMd;
		}

		public String getProdCd() {
			return ProdCd;
		}

		public void setProdCd(String prodCd) {
			ProdCd = prodCd;
		}



		public String getRepeatRqsBss() {
			return RepeatRqsBss;
		}

		public void setRepeatRqsBss(String repeatRqsBss) {
			RepeatRqsBss = repeatRqsBss;
		}

		public DXMMessage getMessage() {
			return Message;
		}

		public void setMessage(DXMMessage message) {
			Message = message;
		}
	}
	
}
